import { _decorator, Component, Label, Node, Tween, tween, UIOpacity, v3 } from 'cc';
import { ToolsHelper } from '../../Frame/Script/toolsHelper';
const { ccclass, property } = _decorator;

@ccclass('TipsViewManager')
export class TipsViewManager extends Component {

    private contentLabel: Label = null;

    onLoad() {
        this.contentLabel = this.node.getChildByName("content").getChildByName("Label").getComponent(Label);
    }

    setTips(str: string) {
        this.contentLabel.string = str;
        Tween.stopAllByTarget(this.node.getComponent(UIOpacity));
        this.node.getComponent(UIOpacity).opacity = 255;
    }

    async setCloseFunc(cb: Function) {
        await ToolsHelper.delayTime(2);
        tween(this.node.getComponent(UIOpacity))
            .to(0.5, { opacity: 0 })
            .call(() => {
                cb && cb();
            })
            .start()
    }

    upMove() {
        let pos = this.node.position;
        let v3p = v3(pos.x, pos.y + 100, pos.z);
        this.node.setPosition(v3p);
    }
}


